package com.yanqu.road.entity.activity.silkroad;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.*;

@FieldTypeAnnotation(tableName = "t_u_silkroad", desc = "南海丝路活动玩家数据")
public class UserSilkRoadData extends DataObject {

    @FieldTypeAnnotation(select = true, update = true, desc = "用户id")
    private long userId;
    @FieldTypeAnnotation(select = true, update = true, desc = "活动id")
    private int activityId;
    @FieldTypeAnnotation(desc = "用户当前旅行下标")
    private int routeIndex;
    @FieldTypeAnnotation(desc = "成就值")
    private int achievement;
    @FieldTypeAnnotation(desc = "积分")
    private long score;
    @FieldTypeAnnotation(desc = "待处理事件")
    private List<Integer> eventIds = new ArrayList<>();
    @FieldTypeAnnotation(desc = "累计打捞到的物品")
    private Map<Integer, Integer> refloatItemMap = new HashMap<>();
    @FieldTypeAnnotation(desc = "当前海域")
    private int nowSea;
    @FieldTypeAnnotation(desc = "当前海域随机到的地图")
    private int mapId;
    @FieldTypeAnnotation(desc = "当前海域剩余的物品")
    private Map<Integer, Set<Integer>> remainSeaItemMap = new HashMap<>();

    @FieldTypeAnnotation(desc = "海域刷新次数")
    private int seaCount;

    public UserSilkRoadData() {
    }

    public UserSilkRoadData(long userId, int activityId) {
        this.userId = userId;
        this.activityId = activityId;
        setInsertOption();
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getRouteIndex() {
        return routeIndex;
    }

    public void setRouteIndex(int routeIndex) {
        if (this.routeIndex != routeIndex) {
            setUpdateOption();
        }
        this.routeIndex = routeIndex;
    }

    public int getAchievement() {
        return achievement;
    }

    public void setAchievement(int achievement) {
        if (this.achievement != achievement) {
            setUpdateOption();
        }
        this.achievement = achievement;
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if (this.score != score) {
            setUpdateOption();
        }
        this.score = score;
    }

    public List<Integer> getEventIds() {
        return eventIds;
    }

    public void setEventIds(List<Integer> eventIds) {
        this.eventIds = eventIds;
    }

    public void addEventId(int eventId) {
        this.eventIds.add(eventId);
        setUpdateOption();
    }

    public void removeEventId(int eventIdx) {
        this.eventIds.remove(eventIdx);
        setUpdateOption();
    }

    public void clearEventIds() {
        this.eventIds.clear();
        setUpdateOption();
    }

    public Map<Integer, Integer> getRefloatItemMap() {
        return refloatItemMap;
    }

    public void setRefloatItemMap(Map<Integer, Integer> refloatItemMap) {
        this.refloatItemMap = refloatItemMap;
    }

    public int getNowSea() {
        return nowSea;
    }

    public void setNowSea(int nowSea) {
        if (this.nowSea != nowSea) {
            setUpdateOption();
        }
        this.nowSea = nowSea;
    }

    public int getMapId() {
        return mapId;
    }

    public void setMapId(int mapId) {
        if (this.mapId != mapId) {
            setUpdateOption();
        }
        this.mapId = mapId;
    }

    public Map<Integer, Set<Integer>> getRemainSeaItemMap() {
        return remainSeaItemMap;
    }

    public void setRemainSeaItemMap(Map<Integer, Set<Integer>> remainSeaItemMap) {
        this.remainSeaItemMap = remainSeaItemMap;
    }

    public List<Integer> getRemainSeaItemList(int seaType) {
        Set<Integer> idSet = remainSeaItemMap.get(seaType);
        if (idSet == null) {
            idSet = new HashSet<>();
            remainSeaItemMap.put(seaType, idSet);
        }
        return new ArrayList<>(idSet);
    }

    public void addRemainSeaItem(int seaType, int itmeId) {
        Set<Integer> idSet = remainSeaItemMap.get(seaType);
        if (idSet == null) {
            idSet = new HashSet<>();
            remainSeaItemMap.put(seaType, idSet);
        }
        idSet.add(itmeId);

        setUpdateOption();
    }


    public void removeRemainSeaItem(int seaType, int itemId) {
        Set<Integer> idSet = remainSeaItemMap.get(seaType);
        if (idSet != null) {
            idSet.remove(itemId);
        }

        setUpdateOption();
    }

    public void clearAllRemainSeaItem(int seaType) {
        Set<Integer> idSet = remainSeaItemMap.get(seaType);
        if (idSet != null) {
            idSet.clear();
        }
        setUpdateOption();
    }

    public void addRefloatItem(int itemId) {
        Integer count = refloatItemMap.getOrDefault(itemId, 0);
        count++;
        refloatItemMap.put(itemId, count);
        setUpdateOption();
    }

    public int getSeaCount() {
        return seaCount;
    }

    public void setSeaCount(int seaCount) {
        if (this.seaCount != seaCount) {
            setUpdateOption();
        }
        this.seaCount = seaCount;
    }
}
